<?php
require_once("vcl/vcl.inc.php");
require_once("lib/db_connection.php");
//Includes
use_unit("components4phpfull/jtjavascript.inc.php");
use_unit("platinumgrid/jtplatinumgrid.inc.php");
use_unit("components4phpfull/jtsitetheme.inc.php");
use_unit("forms.inc.php");
use_unit("extctrls.inc.php");
use_unit("stdctrls.inc.php");

//Class definition
class Route_Job_List extends Page
{
       public $JTJavaScript1 = null;
       public $lblveh = null;
       public $Label1 = null;
       public $imgBack = null;
       public $lblName = null;
       public $lblId = null;
       public $hiddenEmp = null;
       public $JTJobList = null;
       public $imgAdd = null;
       public $hiddenRoute = null;
       public $lblEmpName = null;
       public $lblEmpId = null;
       public $JTSiteTheme1 = null;
       public $Image1 = null;
       function imgAddJSMouseOut($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['imgAdd'].src="image/add_new.png"
       <?php

       }

       function imgAddJSMouseOver($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['imgAdd'].src="image/add_new_blue.png"
       <?php

       }

       function imgBackJSMouseOut($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['imgBack'].src="image/btn_back.png"
       <?php

       }

       function imgBackJSMouseOver($sender, $params)
       {

       ?>
       //Add your javascript code here
         document.images['imgBack'].src="image/btn_back2.png"
       <?php

       }


       function JTJobListShow($sender, $params)
       {

       $query_job = "select * from route_tbl where emp_id='".$this->hiddenEmp->getValue()."'";
       $result_job = mysql_query($query_job)or die(mysql_error());
       $row_job = mysql_fetch_array($result_job);

       $query = "SELECT * FROM rou_jobrecord_tbl WHERE emp_id='".$this->hiddenEmp->getValue()."'";
       $result = mysql_query($query)or die(mysql_error());

        $arr = array();
        while($row = mysql_fetch_array($result))
          {

          $emp = $this->hiddenEmp->getValue();
          $route = $this->hiddenRoute->getValue();

          $strtH = $row['start_hrs'];
          $strtHN = '';
          if($strtH <= 9 && $stopH >= 0)
          {
          $strtHN = '0'.$strtH;
          }
          else
          {
          $strtHN = $row['start_hrs'];
          }

          $strtM = $row['start_min'];
          $strtMN = '';
          if($strtM <= 9 && $stopH >= 0)
          {
          $strtMN = '0'.$strtH;
          }
          else
          {
          $strtMN = $row['start_min'];
          }

          $stopH = $row['stop_hrs'];
          $stopHN = '';
          if($stopH <= 9 && $stopH >= 0)
          {
          $stopHN = '0'.$stopH;
          }
          else
          {
          $stopHN = $row['stop_hrs'];
          }

          $stopM = $row['stop_min'];
          $stopMN = '';
          if($stopM <= 9 && $stopH >= 0)
          {
          $stopMN = '0'.$stopH;
          }
          else
          {
          $stopMN = $row['stop_min'];
          }

          $tools= "<img onclick=window.open('print_locs.php?job_id=".$row['job_id']."','popup','width=850,height=768,scrollbars=yes,resizable=no,toolbar=no,directories=no,location=no,menubar=no,status=no,left=0,top=0'); src='image/print.png' title='Print'>
          <img onclick=js_deleteJob('".$emp."','".$route."','".$row['job_id']."'); src='image/delete.png' title='delete'>";
          ;
          //"<a href=route_job_delete.php?emp=".$emp."&route=".$route."&job=".$row['job_id']."><img src='image/delete_orange.jpg' title='delete' no border></a>";
          $hrs= "<a href=route_job_edit.php?emp=".$emp."&route=".$route."&job=".$row['job_id']." title='edit route job'>".$row_job['start_date']."</a>";


            if($_SESSION['isAdmin']==1)
            {
            $arr[] = array(
                        'Start Date' => $hrs,
                        'End Date' => $row_job['end_date'],
                        'Start' => $strtHN.":".$strtMN,
                        'Stop' => $stopHN.":".$stopMN,
                        'Job/Order No' => $row['job_no'],
                        'Job Location/Name' => $row['location'],
                        'Tools' => $tools
                        );
            }

            if($_SESSION['isAdmin']!=1)
            {
            $arr[] = array(
                        'Start Date' => $row_job['start_date'],
                        'End Date' => $row_job['end_date'],
                        'Start' => $strtHN.":".$strtMN,
                        'Stop' => $stopHN.":".$stopMN,
                        'Job/Order No' => $row['job_no'],
                        'Job Location/Name' => $row['location']
                        );
            }


          }

            $this->JTJobList->setCellData($arr);

       }

       function Route_Job_ListCreate($sender, $params)
       {
       if($_SESSION['isAdmin']!=1)
       {
       $this->imgAdd->setVisible(false);
       }


        $emp_id = $_GET['emp'];
        $this->hiddenEmp->setValue($emp_id);
        $route_id = $_GET['route'];
        $this->hiddenRoute->setValue($route_id);

       $this->imgBack->setLink('route_list.php?emp='.$this->hiddenEmp->getValue());

       $query_emp = "select * from employee_tbl where autoid='".$this->hiddenEmp->getValue()."'";
       $result_emp = mysql_query($query_emp)or die(mysql_error());
       $row_emp = mysql_fetch_array($result_emp);

       $this->lblId->Caption=$row_emp['emp_id'];
       $this->lblName->Caption=$row_emp['lname'].','.$row_emp['fname'];


       $query_veh = "select * from route_tbl where route_id='".$this->hiddenRoute->getValue()."'";
       $result_veh = mysql_query($query_veh)or die(mysql_error());
       $row_veh = mysql_fetch_array($result_veh);

       $this->lblveh->Caption=$row_veh['vehicle'];


       $this->imgAdd->setLink('route_job_create.php?emp='.$this->hiddenEmp->getValue());
       }

}

global $application;

global $Route_Job_List;

//Creates the form
$Route_Job_List=new Route_Job_LIst($application);

//Read from resource file
$Route_Job_List->loadResource(__FILE__);

//Shows the form
$Route_Job_List->show();

?>